/**
 * Created by ZY on 2018/01/06
 */
let _ = require('lodash'),
  util = require('../helper/util'),
  errCode = require('../../conf/errorCode'),
  logger = require('../helper/logger'),
  service = require('../services/userService');

var tagLogger = new logger.TagLogger('USER_CONTROLLER');

exports.getByAccountName = function(req, res, next) {
  let {accountName, page, size} = req.query;
  service.getByAccountName(
    accountName,
    page,
    size,
    util.getHandle(req, res, errCode.GET_POST_BY_POST_ID),
  );
};

exports.blockUserByIds = function(req, res, next) {
  let ids = req.body.userIds;
  service.blockUserByIds(
    ids,
    util.getHandle(req, res, errCode.BLOCK_USER_BY_IDS),
  );
};

exports.modifyUserRole = function(req, res, next) {
  let {role,uid} = req.body;
  service.modifyUserRole(
    uid,
    role,
    util.getHandle(req, res, errCode.BLOCK_USER_BY_IDS),
  );
};
exports.generateMobileMsgCode = function(req, res, next) {
  let {mobile} = req.body;
  service.generateMobileMsgCode(
    mobile,
    util.getHandle(req, res, errCode.GENERATE_MOBILE_MSG_CODE),
  );
};

exports.getUserInfo = function(req, res, next) {
  service.getUserInfo(
    req.cookies.userId,
    util.getHandle(req, res, errCode.GET_USER_INFO),
  );
};

exports.getUserListByNamePrefix = function(req, res, next) {
  let {namePrefix} = req.query;
  service.getUserListByNamePrefix(
    namePrefix,
    util.getHandle(req, res, errCode.GET_POST_BY_POST_ID),
  );
};

exports.getUserByPage = function(req, res, next) {
  let {page, size, namePrefix = ''} = req.query;
  service.getUserByPage(
    namePrefix,
    page,
    size,
    util.getHandle(req, res, errCode.GET_POST_BY_PAGE),
  );
};
